<template>
	<view class="back_color">
		<scroll-view scroll-y class="scroll-container">
			<!-- 改进后的多级联动选择器 -->
			<view class="city-picker">
				<view class="picker-label">选择地区：</view>
				<picker 
					mode="multiSelector" 
					@columnchange="bindMultiPickerColumnChange" 
					:value="multiIndex"
					:range="multiArray"
					@change="onPickerConfirm"
				>
				<!-- 11 -->
					<view >
						{{ selectedArea || '请选择省/市/区' }}
					</view>
				</picker>
			</view>

			<!-- 顶部轮播图 -->
			<view class="smart-padding-wrap">
				<swiper circular :indicator-dots="indicatorDots" :autoplay="autoplay"
					:interval="interval" :duration="duration">
					<swiper-item><image src="/static/quanzhou/city1.png" class="img_wh"></image></swiper-item>
					<swiper-item><image src="/static/quanzhou/city2.png" class="img_wh"></image></swiper-item>
					<swiper-item><image src="/static/quanzhou/city3.png" class="img_wh"></image></swiper-item>
					<swiper-item><image src="/static/quanzhou/city4.png" class="img_wh"></image></swiper-item>
				</swiper>
			</view>

			<!-- 城市介绍 -->
			<view class="city-intro">
				<view class="text_t">泉州介绍</view>
				<view class="text_p">海上丝绸之路起点・泉州</view>
				<view class="text_magin">历史文化：泉州是国务院首批公布的 24 个历史文化名城之一，是古代 “海上丝绸之路” 起点，宋元时期被誉为 “东方第一大港”。</view>
				<view class="text_magin">著名景点：清源山、开元寺、泉州清净寺、崇武古城、洛阳桥等。</view>
				<view>特色文化：拥有南音、木偶戏和闽南建筑等丰富的非物质文化遗产。</view>
			</view>

			<!-- 媒体展示 -->
			<view class="TV">
				<view class="media-show">
					<video
						:src="quanzhou.video"
						:poster="quanzhou.poster"
						controls
						class="city-video"
					></video>
					
				</view>
			</view>

			<!-- 偏好设置 -->
			<view class="way">
				<view class="preference-setting">
					<view class="transport">
						<text>出行方式：</text>
						<radio-group @change="onTransportChange">
							<radio :value="item" v-for="item in transportOptions" :key="item">
								{{item}}
							</radio>
						</radio-group>
					</view>
					<view class="recommend-switch">
						<text>显示推荐景点：</text>
						<switch v-model="showRecommend" />
					</view>
					<view class="explore-radius">
						<text>探索半径：{{radius}}km</text>
						<slider
							:value="radius"
							@change="onRadiusChange"
							min="1"
							max="20"
							class="radius-slider"
						/>
					</view>
				</view>

				<view class="explore-progress">
					<text>探索进度：</text>
					<progress :percent="100" show-info />
				</view>
			</view>
			<view class="view_h"></view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 统一管理泉州相关资源和信息
			quanzhou: {
				video: '/static/quanzhou/city-video.mp4',
				poster: '/static/quanzhou/city1.png',
			},
			// 地区数据结构优化 - 采用更清晰的嵌套结构
			areaData: [
				{
					name: '福建省',
					cities: [
						{
							name: '泉州',
							districts: ['丰泽区', '南安市', '石狮市', '晋江市', '惠安县']
						},
						{
							name: '莆田',
							districts: ['城厢区', '涵江区', '荔城区', '秀屿区']
						},
						{
							name: '福州',
							districts: ['鼓楼区', '台江区', '仓山区', '晋安区']
						}
					]
				},
				{
					name: '江西省',
					cities: [
						{
							name: '南昌',
							districts: ['南昌县', '西湖区', '东湖区', '青山湖区']
						},
						{
							name: '赣州',
							districts: ['章贡区', '南康区', '赣县区', '信丰县']
						},
						{
							name: '九江',
							districts: ['浔阳区', '濂溪区', '柴桑区', '武宁县']
						}
					]
				}
			],
			// 用于picker展示的数组
			multiArray: [[], [], []],
			// 选中的索引
			multiIndex: [0, 0, 0],
			// 选中的地区文本
			selectedArea: '',
			
			transportOptions: ['公交', '自驾', '步行'],
			selectedTransport: '公交',
			showRecommend: true,
			radius: 9,
			indicatorDots: true,
			autoplay: true,
			interval: 2000,
			duration: 500
		};
	},
	onLoad() {
		// 初始化地区选择器数据
		this.initAreaData();
	},
	methods: {
		// 初始化地区数据
		initAreaData() {
			// 提取省份数据
			this.multiArray[0] = this.areaData.map(province => province.name);
			
			// 提取默认省份的城市数据
			this.multiArray[1] = this.areaData[0].cities.map(city => city.name);
			
			// 提取默认城市的区县数据
			this.multiArray[2] = this.areaData[0].cities[0].districts;
			
			// 设置默认选中地区文本
			this.updateSelectedAreaText();
		},
		
		// 更新选中地区的文本显示
		updateSelectedAreaText() {
			const province = this.multiArray[0][this.multiIndex[0]];
			const city = this.multiArray[1][this.multiIndex[1]];
			const district = this.multiArray[2][this.multiIndex[2]];
			this.selectedArea = `${province},${city},${district}`;
		},
		
		// 多级选择器列变化事件
		bindMultiPickerColumnChange(e) {
			const { column, value } = e.detail;
			const newMultiIndex = [...this.multiIndex];
			newMultiIndex[column] = value;
			
			// 根据列索引处理联动逻辑
			switch (column) {
				case 0: // 省份变化
					// 重置城市和区县索引
					newMultiIndex[1] = 0;
					newMultiIndex[2] = 0;
					// 更新城市列表
					this.multiArray[1] = this.areaData[value].cities.map(city => city.name);
					// 更新区县列表
					this.multiArray[2] = this.areaData[value].cities[0].districts;
					break;
					
				case 1: // 城市变化
					// 重置区县索引
					newMultiIndex[2] = 0;
					// 获取当前选中的省份索引
					const provinceIndex = newMultiIndex[0];
					// 更新区县列表
					this.multiArray[2] = this.areaData[provinceIndex].cities[value].districts;
					break;
					
				// 区县变化不需要额外处理
			}
			
			this.multiIndex = newMultiIndex;
			this.updateSelectedAreaText();
		},
		
		// 选择器确认选择事件
		onPickerConfirm() {
			// 可以在这里添加选择确认后的逻辑，如请求该地区数据等
			uni.showToast({
				title: `已选择: ${this.selectedArea}`,
				icon: 'none',
				duration: 1500
			});
		},
		
		onTransportChange(e) {
			this.selectedTransport = e.detail.value;
		},
		
		onRadiusChange(e) {
			this.radius = e.detail.value;
		},
	}
};
</script>

<style>
@import '../../../lib/css/city.css';

/* 新增picker样式优化 */
.picker-label {
	font-size: 30rpx;
	color: #333;
	margin-bottom: 10rpx;
}

.picker-text {
	border: 1px solid #bebebe;
	padding: 15rpx;
	border-radius: 8rpx;
	background-color: #fff;
	font-size: 28rpx;
}
</style>